package com.orderplus.opshop.core.data;

import java.util.Map;

/**
 * 数据格式转换类，目前为DTO类与ENTITY类的转换
 * Title:
 * Description:
 * Company: Copyright @ 2019 OrderPlus 版权所有
 *
 * @version 1.0 初稿
 * @author: mhj
 * @date: 2014年12月29日下午3:10:45
 */
public abstract class AbstractExchanger<DTO, ENTITY> {
	public abstract DTO newInstanceDto();

	public abstract ENTITY newInstanceEntity();

	public abstract void entityFillDto(ENTITY entity, DTO dto);

	public abstract void dtoFillEntity(DTO dto, ENTITY entity);

	public abstract void mapFillDto(Map<String, Object> map, DTO dto);

	public abstract void mapFillEntity(Map<String, Object> map, ENTITY entity);

	public DTO entityToDto(ENTITY entity) {
		DTO dto = newInstanceDto();
		entityFillDto(entity, dto);
		return dto;
	}

	public ENTITY dtoToEntity(DTO dto) {
		ENTITY entity = newInstanceEntity();
		dtoFillEntity(dto, entity);
		return entity;
	}

	public DTO mapToDto(Map<String, Object> map) {
		DTO dto = newInstanceDto();
		mapFillDto(map, dto);
		return dto;
	}

	public ENTITY mapToEntity(Map<String, Object> map) {
		ENTITY entity = newInstanceEntity();
		mapFillEntity(map, entity);
		return entity;
	}

}
